//
//  PBSeriveDetailController.m
//  PBHomeDemo
//
//  Created by Playboy on 2018/5/12.
//  Copyright © 2018年 tmkj. All rights reserved.
//

#import "PBSeriveDetailController.h"
#import "PBMySerivDetailCollectionCell.h"

static NSString * const kPBMySerivDetailCollectionCell = @"PBMySerivDetailCollectionCell";

@interface PBSeriveDetailController ()<UICollectionViewDelegate,UICollectionViewDataSource>
@property (weak, nonatomic) IBOutlet UILabel *homeInfoLabel;
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;
@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *desLabel;
@property (weak, nonatomic) IBOutlet UICollectionView *collectView;
@property (weak, nonatomic) IBOutlet UILabel *statesLabel;
@property (weak, nonatomic) IBOutlet UIView *desView;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *viewHeightConstraint;

@end

@implementation PBSeriveDetailController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configure];
}

- (void)configure {
    [self configureView];
    [self configureData];
}
- (void)configureView {
     UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
     layout.itemSize = CGSizeMake((kScreenWidth-30-20-30)/4, 80);
//     layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
     layout.minimumLineSpacing = 10;
     self.collectView.collectionViewLayout = layout;
     self.collectView.delegate = self;
     self.collectView.dataSource = self;
     [self.collectView registerNib:[UINib nibWithNibName:kPBMySerivDetailCollectionCell bundle:nil] forCellWithReuseIdentifier:kPBMySerivDetailCollectionCell];
    self.desView.layer.borderWidth = 1.0f;
    self.desView.layer.borderColor = [UIColor tm_separationBgColor].CGColor;
    self.homeInfoLabel.text = self.model.houseName;
    self.nameLabel.text = self.model.userName;
    self.phoneLabel.text = self.model.phone;
    self.desLabel.text = self.model.des;
    if (self.model.status == 1) {
        self.statesLabel.text = @"待处理";
    }else if (self.model.status == 2){
        self.statesLabel.text = @"处理中";
    }else if (self.model.status == 3){
        self.statesLabel.text = @"已处理";
    }else if (self.model.status == 4){
        self.statesLabel.text = @"已撤销";
    }else if (self.model.status == 5){
        self.statesLabel.text = @"已拒绝";
    }
     
     
     if (self.model.imgs.count == 0) {
          self.viewHeightConstraint.constant = 100;
     }else if (self.model.imgs.count <= 4){
          self.viewHeightConstraint.constant = 150;
     }else {
          self.viewHeightConstraint.constant = 250;
     }
}
- (void)configureData {
}

#pragma mark - <UICollectionViewDelegate,UICollectionViewDataSource>
- (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView {
     return 1;
}
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
     return self.model.imgs.count;
}
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
     PBMySerivDetailCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:kPBMySerivDetailCollectionCell forIndexPath:indexPath];
     [cell refreshWithImageString:self.model.imgs[indexPath.row][@"url"]];
     return cell;
}


#pragma mark - super
- (void)resetNavigationBarItems {
    [super resetNavigationBarItems];
    self.title = @"报修详情";
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
